package cn.ekuma.epos.analysis.front.product.model;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.openbravo.pos.base.AppLocal;
import org.apache.commons.lang.ArrayUtils;

import com.openbravo.bean.erp.viewbean.FrontProductAnalysisInfo;

import com.openbravo.pos.util.RoundUtils;

import cn.ekuma.data.ui.swing.AbstractDTOTableModel;
import cn.ekuma.epos.bean.util.ProductLocationStateHelper;

public class ProductPosSellAnalysisTableModel extends AbstractDTOTableModel<FrontProductAnalysisInfo>{
  
    @Override
	public Class<?> getColumnClass(int column) {
    	if(ArrayUtils.contains(doubleColumn, column))
    		return Double.class;
		return super.getColumnClass(column);
	}
    
    static int[] doubleColumn={1,2,3,4,7,8,9,11,12,13,14};

	public static String[] COLUMNS_Pref=new String[]{
           AppLocal.getIntString("label.prodname"),
           "POS数量小计",
           "POS金额小计",
           "POS成本小计",
           "POS利润小计",
           AppLocal.getIntString("label.prodcategory"),
           AppLocal.getIntString("label.prodbarcode"),
           AppLocal.getIntString("label.storeNum"),
           AppLocal.getIntString("label.minimum"),
           AppLocal.getIntString("label.maximum"),
           AppLocal.getIntString("label.productLocationState"),    
           AppLocal.getIntString("label.prodpricebuy"),
           AppLocal.getIntString("label.prodpricesell"),
           AppLocal.getIntString("label.baseCustomerPrice"),
           AppLocal.getIntString("label.WholesalePrice"),
           AppLocal.getIntString("label.prodref"),
           AppLocal.getIntString("label.product.origin"),//产地
           AppLocal.getIntString("label.product.m_similarCode"),
           AppLocal.getIntString("label.prodcut.m_sManufacturer"),//品牌
           AppLocal.getIntString("label.product.m_iDurability"),//质保
           AppLocal.getIntString("label.produnits"),//计量单位
           AppLocal.getIntString("label.product.quantity"),//装数
           "demo"//补助的
    };

    public Object getValueAt(int rowIndex, int columnIndex) {
    	FrontProductAnalysisInfo selected=objs.get(rowIndex); 
        if(columnIndex<COLUMNS_Pref.length)
        	 switch (columnIndex) {
             case 0:
                 return selected.getM_sName();
             case 1:
                 return selected.getMult();
             case 2:
                 return selected.getTotal();
             case 3:
                 return selected.getCost();
             case 4:
                 return RoundUtils.substract(selected.getTotal(),selected.getCost());
             case 5:
                 return selected.getCategory();
             case 6:
                 return selected.getM_sCode();
             case 7:
                 return selected.getMultiply();
             case 8:
                 return selected.getMinimum();
             case 9:
                 return selected.getMaximum();
             case 10:
                 return ProductLocationStateHelper.getProductLocationState(selected.getState());
            case 11:
                return selected.getM_dPriceBuy();
            case 12:
                return selected.getM_dPriceSell();
            case 13:
                return selected.getM_dCustomerPrice();
            case 14:
                return selected.getM_dWholesalePrice();    
            case 15:
                return selected.getM_sRef();
            case 16:
                return selected.getM_origin();
            case 17:
                return selected.getM_sSimilarCode();
            case 18:
                return selected.getM_sManufacturer();
            case 19:
                return selected.getM_iDurability();
            case 20:
                return selected.getM_unit();
            case 21:
                return selected.getM_quantity();
            case 22:
                return Math.round(selected.getMultiply());
        }
        return null;
    }

	@Override
	public String[] getColumnNames() {
		return COLUMNS_Pref;
	}
}